<template>
  <div class="audit" v-wechat="$route.meta.title">
    <div class="main">
      <div class="titles">
        <i id="i"></i>
        <h2>
          <span>{{$t('message.shyj')}}</span>
          <span class="todetail" @click="toDetail($route.query.id)">{{$t('lackMsg.ckcgxq')}}</span>
        </h2>
      </div>
      <van-cell-group>
        <van-field
          v-model="audit"
          rows="3"
          autosize
          type="textarea"
          maxlength="512"
          class="textareas"
          :placeholder="$t('addMsg.p-shyj')"
          show-word-limit
        />
      </van-cell-group>
    </div>
    <div class="footer">
      <van-button type="info" @click="pass" class="btn">{{$t('message.shtg')}}</van-button>
      <van-button type="default" @click="turn" class="btn">{{$t('message.bh')}}</van-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      audit: "", //追踪意见
      fileList: []
    };
  },
  mounted() {},
  methods: {
    pass() {
      if (this.audit !== "") {
        //审核通过
        if (this.$route.query.auditClassification == 0) {
          //普通审核
          if (this.$route.query.obj === "CONTRACT") {
            this.$axios
              .get("/api/contract/contractAuditPass", {
                //合同审核通过
                id: this.$route.query.id,
                auditComment: this.audit
              })
              .then(res => {
                if (res.data.code === 200) {
                  this.$toast(res.data.message);
                  this.$router.push({
                    path: "/home"
                  });
                } else {
                  this.$toast(res.data.message);
                }
              });
          } else {
            //成果审核通过
            this.$axios
              .get("/api/releaseResult/resultAuditPass", {
                id: this.$route.query.id,
                auditComment: this.audit
              })
              .then(res => {
                console.log(res);
                if (res.data.code === 200) {
                  this.$toast(res.data.message);
                  this.$router.push({
                    path: "/home"
                  });
                } else {
                  this.$toast(res.data.message);
                }
              });
          }
        } else {
          //   追踪审核
          if (this.$route.query.obj === "CONTRACT") {
            this.$axios
              .get("/api/contractTrack/auditPassMobile", {
                //合同追踪审核通过
                id: this.$route.query.id,
                auditComment: this.audit
              })
              .then(res => {
                console.log(res);
                if (res.data.code === 200) {
                  this.$toast(res.data.message);
                  this.$router.push({
                    path: "/home"
                  });
                } else {
                  this.$toast(res.data.message);
                }
              });
          } else {
            //成果追踪审核通过
            this.$axios
              .get("/api/releaseResultTrack/auditPassMobile", {
                id: this.$route.query.id,
                auditComment: this.audit
              })
              .then(res => {
                console.log(res);
                if (res.data.code === 200) {
                  this.$toast(res.data.message);
                  this.$router.push({
                    path: "/home"
                  });
                } else {
                  this.$toast(res.data.message);
                }
              });
          }
        }
      } else {
        this.$toast(this.$t("addMsg.p-shyj"));
      }
    },
    turn() {
      // 审核内容为空
      if (this.audit !== "") {
        this.$dialog
          .confirm({
            confirmButtonColor: "#FE8D01",
            message: this.$t("message.qrbhgcsh")
          })
          .then(() => {
            if (this.$route.query.auditClassification == 0) {
              //普通审核
              if (this.$route.query.obj === "CONTRACT") {
                this.$axios
                  .get("/api/contract/contractAuditReject", {
                    //合同审核驳回
                    id: this.$route.query.id,
                    auditComment: this.audit
                  })
                  .then(res => {
                    console.log(res);
                    if (res.data.code === 200) {
                      this.$toast(res.data.message);
                      this.$router.push({
                        path: "/home"
                      });
                    } else {
                      this.$toast(res.data.message);
                    }
                  });
              } else {
                //成果审核驳回
                this.$axios
                  .get("/api/releaseResult/resultAuditReject", {
                    id: this.$route.query.id,
                    auditComment: this.audit
                  })
                  .then(res => {
                    console.log(res);
                    if (res.data.code === 200) {
                      this.$toast(res.data.message);
                      this.$router.push({
                        path: "/home"
                      });
                    } else {
                      this.$toast(res.data.message);
                    }
                  });
              }
            } else {
              //   追踪驳回
              if (this.$route.query.obj === "CONTRACT") {
                this.$axios
                  .get("/api/contractTrack/auditRejectMobile", {
                    //追踪合同审核驳回
                    id: this.$route.query.id,
                    auditComment: this.audit
                  })
                  .then(res => {
                    console.log(res);
                    if (res.data.code === 200) {
                      this.$toast(res.data.message);
                      this.$router.push({
                        path: "/home"
                      });
                    } else {
                      this.$toast(res.data.message);
                    }
                  });
              } else {
                //追踪成果审核驳回
                this.$axios
                  .get("/api/releaseResultTrack/auditRejectMobile", {
                    id: this.$route.query.id,
                    auditComment: this.audit
                  })
                  .then(res => {
                    console.log(res);
                    if (res.data.code === 200) {
                      this.$toast(res.data.message);
                      this.$router.push({
                        path: "/home"
                      });
                    } else {
                      this.$toast(res.data.message);
                    }
                  });
              }
            }
          })
          .catch(() => {
            // on cancel
          });
        //驳回审核
      } else {
        this.$toast(this.$t("addMsg.p-shyj"));
      }
    },
    toDetail(id) {
      if (this.$route.query.obj === "CONTRACT") {
        this.$router.push({
          path: "/contractDetail",
          query: {
            id: this.$route.query.id
          }
        });
      } else {
        this.$router.push({
          path: "/achievementsDetail",
          query: {
            id: this.$route.query.id
          }
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.audit {
  height: 100%;
  background: transparent;
  padding: 15px 15px 0;
  overflow: auto;
}
.main {
  background: #fff;
  padding: 0 15px 17px;
  border-radius: 8px;
  .update {
    color: #999999;
    font-size: 12px;
    .up {
      width: 102px;
      height: 32px;
      margin: 20px 0 9px;
      color: #fff;
      font-size: 14px;
    }
  }
}
.textareas {
  border: 1px solid #e6e9ee;
  border-radius: 5px;
  /*width:95%;*/
  /*height:110px;*/
  /*margin:0 auto;*/
}
.titles {
  height: 47px;
  font-size: 14px;
  /*line-height: 48px;*/
  font-family: PingFangHK-Medium;
  color: #212121;
  display: flex;
  align-items: center;
  i#i {
    width: 5px;
    height: 15px;
    background: #ffbc3a;
  }
  h2 {
    margin-left: 6px;
    flex: 1;
    display: flex;
    justify-content: space-between;
    .todetail {
      color: #ffbc39;
      font-size: 12px;
      text-align: right;
    }
  }
}
.footer {
  margin-top: 48px;
  padding: 0 15px;
  .btn {
    width: 100%;
    height: 40px;
    font-size: 16px;
    margin-bottom: 15px;
    border-radius: 20px;
  }
  .btn:first-child {
    background-image: linear-gradient(90deg, #fecf47 0%, #ffbc39 100%);
    border: none;
  }
}
</style>
